﻿package Engine.RMI
{
    import Engine.flash.*;
    import Framework.Protocol.*;

    public class Communicator extends EventSender
    {
        private var _connecting:Boolean;
        private var _connected:Boolean;
        private var _url:String;
        private var _connection:RMIConnection;
        private var _session:Session;
        private var _sessionEvent:IRMISessionEvent;
        private var _prepareCommandHandler:IRMIPrepareCommandHandler;

        public function Communicator(param1:IProtocol)
        {
            this._connecting = false;
            this._connected = false;
            this._connection = new RMIConnection(param1);
            return;
        }// end function

        public function connect() : Boolean
        {
            var array:Array;
            var ip:String;
            var port:int;
            this._connecting = true;
            try
            {
                this._connection.session = this.session;
                array = this.url.split(":");
                if (array.length == 2)
                {
                    ip = array[0];
                    port = parseInt(array[1]);
                }
                else
                {
                    return false;
                }
                this.connection.connect(ip, port);
                return true;
            }
            catch (ex:Error)
            {
                _connecting = false;
                trace("Communicator::connect.connect error");
            }
            return false;
        }// end function

        public function set connecting(param1:Boolean) : void
        {
            this._connecting = param1;
            return;
        }// end function

        public function get connecting() : Boolean
        {
            return this._connecting;
        }// end function

        public function set connected(param1:Boolean) : void
        {
            this._connected = param1;
            return;
        }// end function

        public function get connected() : Boolean
        {
            return this._connected;
        }// end function

        public function set url(param1:String) : void
        {
            this._url = param1;
            return;
        }// end function

        public function get url() : String
        {
            return this._url;
        }// end function

        public function get connection() : RMIConnection
        {
            return this._connection;
        }// end function

        public function set session(param1:Session) : void
        {
            this._session = param1;
            return;
        }// end function

        public function get session() : Session
        {
            return this._session;
        }// end function

        public function set sessionEvent(event:IRMISessionEvent) : void
        {
            this._sessionEvent = event;
            return;
        }// end function

        public function get sessionEvent() : IRMISessionEvent
        {
            return this._sessionEvent;
        }// end function

        public function set prepareCommandHandler(param1:IRMIPrepareCommandHandler) : void
        {
            this._prepareCommandHandler = param1;
            return;
        }// end function

        public function get prepareCommandHandler() : IRMIPrepareCommandHandler
        {
            return this._prepareCommandHandler;
        }// end function

    }
}
